1 /*
2 * Angkor Web Framework
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */
7 package com.tirsen.angkor.beans;
8
9 import com.tirsen.angkor.event.ChangeListener;
10 import com.tirsen.angkor.event.ChangeSource;
11 import com.tirsen.angkor.event.ChangeSourceHelper;
12 import com.tirsen.angkor.widget.ValueModel;
13
14 import java.io.Serializable;
15
16
17 /***
18 * A JavaBeanModel acts as the proxy for JavaBean instances which may or may not actually
19 * exist enabling them to be lazily evaluated only when a view actually requests the value
20 * of the JavaBean. Useful when creating views which should be bound to properties of JavaBeans
21 * but the view is not yet visible and the JavaBean is not yet instantiated. Also has a lot of
22 * utility methods for creating various models bound to the JavaBean so it may be useful even if
23 * the JavaBean actually exists. For this reason the name <code>JavaBeanModel</code> may be a little bit
24 * inaccurate, maybe <code>JavaBeanModel</code> may be better.
25 *
26 * <!-- $Id: JavaBeanModel.java,v 1.2 2002/10/09 21:37:37 tirsen Exp $ -->
27 *
28 * @author $Author: tirsen $
29 * @version $Revision: 1.2 $
30 */
31 public class JavaBeanModel implements Serializable, ChangeSource
32 {
33 private Object valueObject;
34 private ValueModel model;
35 private Class objectClass;
36 private ChangeSourceHelper changeSourceHelper = new ChangeSourceHelper(this);
37
38 public JavaBeanModel(Class objectClass)
39 {
40 this.objectClass = objectClass;
41 }
42
43 public JavaBeanModel(ValueModel model)
44 {
45 this.model = model;
46 }
47
48 public JavaBeanModel(Object valueObject)
49 {
50 setValueObject(valueObject);
51 }
52
53 public void setValueObject(Object valueObject)
54 {
55 this.valueObject = valueObject;
56 changeSourceHelper.signalChangeEvent();
57 }
58
59 public Object getObject()
60 {
61 Object object = valueObject;
62 if (object == null && model != null) object = model.getValue();
63 return object;
64 }
65
66 public Class getObjectClass()
67 {
68 Class klass = objectClass;
69 if (klass == null && valueObject != null) klass = valueObject.getClass();
70 if (klass == null && model != null) klass = model.getValueClass();
71 return klass;
72 }
73
74 public ValueModel getValue(String expression)
75 {
76 return new PropertyValueModel(this, expression);
77 }
78
79 public JavaBeanModel getJavaBean(String expression)
80 {
81 return new JavaBeanModel(getValue(expression));
82 }
83
84 public void addChangeListener(ChangeListener listener)
85 {
86 changeSourceHelper.addChangeListener(listener);
87 }
88
89 public void removeChangeListener(ChangeListener listener)
90 {
91 changeSourceHelper.removeChangeListener(listener);
92 }
93 }
This page was automatically generated by Maven